import router from './router'
import { useAppStoreWithOut } from '@/store/modules/app'
import { UserType } from '@/api/login/types'
import { useRouter } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { useTitle } from '@/hooks/web/useTitle'
import { useNProgress } from '@/hooks/web/useNProgress'
import { usePermissionStoreWithOut } from '@/store/modules/permission'
import { usePageLoading } from '@/hooks/web/usePageLoading'
import { NO_REDIRECT_WHITE_LIST } from '@/constants'
import { useUserStoreWithOut } from '@/store/modules/user'
import { signinRedirect ,getUserInfo} from '@/utils/oidc/index.js'
import config from '@/config/index'


const { start, done } = useNProgress()

const { loadStart, loadDone } = usePageLoading()

router.beforeEach(async (to, from, next) => {
  start()
  loadStart()
   // 判断是否登录
   const oidcUser = await getUserInfo()
   console.log(oidcUser,'oidcUerser====')
   if(oidcUser){
    console.log('有oidc的数据--==')
   }else{
    if (to.path === '/login' || to.path === '/transfer') {
      console.log('去往登录页===或者中转页')
      next()
    } else {
      console.log('去别的页面')

      // signinRedirect()
    }
   }

})


router.afterEach((to) => {
  useTitle(to?.meta?.title as string)
  done() // 结束Progress
  loadDone()
})
